GObject parent_instance;
};
-typedef struct _GskVulkanVertex GskVulkanVertex;
+typedef struct _GskVulkanBlendInstance GskVulkanBlendInstance;
-struct _GskVulkanVertex
+struct _GskVulkanBlendInstance
{
- float x;
- float y;
- float tex_x;
- float tex_y;
+ float rect[4];
+ float tex_rect[4];
};
G_DEFINE_TYPE (GskVulkanBlendPipeline, gsk_vulkan_blend_pipeline, GSK_TYPE_VULKAN_PIPELINE)
static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
{
.binding = 0,
- .stride = 4 * sizeof (float),
- .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
+ .stride = sizeof (GskVulkanBlendInstance),
+ .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
}
};
static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
{
.location = 0,
.binding = 0,
- .format = VK_FORMAT_R32G32_SFLOAT,
- .offset = 0,
+ .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendInstance, rect),
},
{
.location = 1,
.binding = 0,
- .format = VK_FORMAT_R32G32_SFLOAT,
- .offset = 2 * sizeof (float),
+ .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendInstance, tex_rect),
}
};
static const VkPipelineVertexInputStateCreateInfo info = {
gsize
gsk_vulkan_blend_pipeline_count_vertex_data (GskVulkanBlendPipeline *pipeline)
{
- return sizeof (GskVulkanVertex) * 6;
+ return sizeof (GskVulkanBlendInstance);
}
void
guchar *data,
const graphene_rect_t *rect)
{
- GskVulkanVertex *vertices = (GskVulkanVertex *) data;
-
- vertices[0] = (GskVulkanVertex) { rect->origin.x, rect->origin.y, 0.0, 0.0 };
- vertices[1] = (GskVulkanVertex) { rect->origin.x + rect->size.width, rect->origin.y, 1.0, 0.0 };
- vertices[2] = (GskVulkanVertex) { rect->origin.x, rect->origin.y + rect->size.height, 0.0, 1.0 };
- vertices[3] = (GskVulkanVertex) { rect->origin.x, rect->origin.y + rect->size.height, 0.0, 1.0 };
- vertices[4] = (GskVulkanVertex) { rect->origin.x + rect->size.width, rect->origin.y, 1.0, 0.0 };
- vertices[5] = (GskVulkanVertex) { rect->origin.x + rect->size.width, rect->origin.y + rect->size.height, 1.0, 1.0 };
+ GskVulkanBlendInstance *instance = (GskVulkanBlendInstance *) data;
+
+ instance->rect[0] = rect->origin.x;
+ instance->rect[1] = rect->origin.y;
+ instance->rect[2] = rect->size.width;
+ instance->rect[3] = rect->size.height;
+ instance->tex_rect[0] = 0.0;
+ instance->tex_rect[1] = 0.0;
+ instance->tex_rect[2] = 1.0;
+ instance->tex_rect[3] = 1.0;
}
gsize
gsize n_commands)
{
vkCmdDraw (command_buffer,
- n_commands * 6, 1,
- offset, 0);
+ 6, n_commands,
+ 0, offset);
- return n_commands * 6;
+ return n_commands;
}
const char *name;
GskVulkanPipeline * (* create_func) (GskVulkanPipelineLayout *layout, const char *name, VkRenderPass render_pass);
} pipeline_info[GSK_VULKAN_N_PIPELINES] = {
- { "blit", gsk_vulkan_blend_pipeline_new },
+ { "blend", gsk_vulkan_blend_pipeline_new },
+ { "blend-clip", gsk_vulkan_blend_pipeline_new },
+ { "blend-clip-rounded", gsk_vulkan_blend_pipeline_new },
{ "color", gsk_vulkan_color_pipeline_new },
{ "color-clip", gsk_vulkan_color_pipeline_new },
{ "color-clip-rounded", gsk_vulkan_color_pipeline_new },
case GSK_CAIRO_NODE:
if (gsk_cairo_node_get_surface (node) == NULL)
return;
- if (!gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
+ if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
+ pipeline_type = GSK_VULKAN_PIPELINE_BLEND;
+ else if (constants->clip.type == GSK_VULKAN_CLIP_RECT)
+ pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP;
+ else if (constants->clip.type == GSK_VULKAN_CLIP_ROUNDED_CIRCULAR)
+ pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP_ROUNDED;
+ else
FALLBACK ("Cairo nodes can't deal with clip type %u\n", constants->clip.type);
op.type = GSK_VULKAN_OP_SURFACE;
- op.render.pipeline = gsk_vulkan_render_get_pipeline (render, GSK_VULKAN_PIPELINE_BLIT);
+ op.render.pipeline = gsk_vulkan_render_get_pipeline (render, pipeline_type);
g_array_append_val (self->render_ops, op);
return;
case GSK_TEXTURE_NODE:
- if (!gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
+ if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
+ pipeline_type = GSK_VULKAN_PIPELINE_BLEND;
+ else if (constants->clip.type == GSK_VULKAN_CLIP_RECT)
+ pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP;
+ else if (constants->clip.type == GSK_VULKAN_CLIP_ROUNDED_CIRCULAR)
+ pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP_ROUNDED;
+ else
FALLBACK ("Texture nodes can't deal with clip type %u\n", constants->clip.type);
op.type = GSK_VULKAN_OP_TEXTURE;
- op.render.pipeline = gsk_vulkan_render_get_pipeline (render, GSK_VULKAN_PIPELINE_BLIT);
+ op.render.pipeline = gsk_vulkan_render_get_pipeline (render, pipeline_type);
g_array_append_val (self->render_ops, op);
return;
g_assert_not_reached ();
return;
}
- op.render.pipeline = gsk_vulkan_render_get_pipeline (render, GSK_VULKAN_PIPELINE_BLIT);
+ op.render.pipeline = gsk_vulkan_render_get_pipeline (render, GSK_VULKAN_PIPELINE_BLEND);
g_array_append_val (self->render_ops, op);
}
#undef FALLBACK
G_BEGIN_DECLS
typedef enum {
- GSK_VULKAN_PIPELINE_BLIT,
+ GSK_VULKAN_PIPELINE_BLEND,
+ GSK_VULKAN_PIPELINE_BLEND_CLIP,
+ GSK_VULKAN_PIPELINE_BLEND_CLIP_ROUNDED,
GSK_VULKAN_PIPELINE_COLOR,
GSK_VULKAN_PIPELINE_COLOR_CLIP,
GSK_VULKAN_PIPELINE_COLOR_CLIP_ROUNDED,
--- /dev/null
+#version 420 core
+
+struct RoundedRect {
+ vec4 bounds;
+ vec4 corners;
+};
+
+layout(location = 0) in vec2 inPos;
+layout(location = 1) in vec2 inTexCoord;
+layout(location = 2) in flat vec4 inClipBounds;
+layout(location = 3) in flat vec4 inClipWidths;
+
+layout(set = 0, binding = 0) uniform sampler2D inTexture;
+
+layout(location = 0) out vec4 color;
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+float clip(vec2 pos, RoundedRect r) {
+ vec2 ref_tl = r.bounds.xy + vec2( r.corners.x, r.corners.x);
+ vec2 ref_tr = r.bounds.zy + vec2(-r.corners.y, r.corners.y);
+ vec2 ref_br = r.bounds.zw + vec2(-r.corners.z, -r.corners.z);
+ vec2 ref_bl = r.bounds.xw + vec2( r.corners.w, -r.corners.w);
+
+ float d_tl = distance(pos, ref_tl);
+ float d_tr = distance(pos, ref_tr);
+ float d_br = distance(pos, ref_br);
+ float d_bl = distance(pos, ref_bl);
+
+ float pixels_per_fragment = length(fwidth(pos.xy));
+ float nudge = 0.5 * pixels_per_fragment;
+ vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - r.corners + nudge;
+
+ bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
+ pos.x > ref_tr.x && pos.y < ref_tr.y,
+ pos.x > ref_br.x && pos.y > ref_br.y,
+ pos.x < ref_bl.x && pos.y > ref_bl.y);
+
+ float distance_from_border = dot(vec4(is_out),
+ max(vec4(0.0, 0.0, 0.0, 0.0), distances));
+
+ // Move the distance back into pixels.
+ distance_from_border /= pixels_per_fragment;
+ // Apply a more gradual fade out to transparent.
+ //distance_from_border -= 0.5;
+
+ return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
+}
+
+void main()
+{
+ RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
+
+ color = texture (inTexture, inTexCoord) * clip (inPos, r);
+}
--- /dev/null
+#version 420 core
+
+layout(location = 0) in vec4 inRect;
+layout(location = 1) in vec4 inTexRect;
+
+layout(push_constant) uniform PushConstants {
+ mat4 mvp;
+ vec4 clip_bounds;
+ vec4 clip_widths;
+ vec4 clip_heights;
+} push;
+
+layout(location = 0) out vec2 outPos;
+layout(location = 1) out vec2 outTexCoord;
+layout(location = 2) out flat vec4 outClipBounds;
+layout(location = 3) out flat vec4 outClipWidths;
+
+out gl_PerVertex {
+ vec4 gl_Position;
+};
+
+vec2 offsets[6] = { vec2(0.0, 0.0),
+ vec2(1.0, 0.0),
+ vec2(0.0, 1.0),
+ vec2(0.0, 1.0),
+ vec2(1.0, 0.0),
+ vec2(1.0, 1.0) };
+
+vec4 intersect(vec4 a, vec4 b)
+{
+ a = vec4(a.xy, a.xy + a.zw);
+ b = vec4(b.xy, b.xy + b.zw);
+ vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
+ if (any (greaterThanEqual (result.xy, result.zw)))
+ return vec4(0.0,0.0,0.0,0.0);
+ return vec4(result.xy, result.zw - result.xy);
+}
+
+void main() {
+ vec4 rect = intersect(inRect, push.clip_bounds);
+ vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
+ gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
+
+ outPos = pos;
+ outClipBounds = push.clip_bounds;
+ outClipWidths = push.clip_widths;
+
+ vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
+ rect.zw / inRect.zw);
+ texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
+ inTexRect.zw * texrect.zw);
+ outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
+}
--- /dev/null
+#version 420 core
+
+layout(location = 0) in vec2 inTexCoord;
+
+layout(set = 0, binding = 0) uniform sampler2D inTexture;
+
+layout(location = 0) out vec4 color;
+
+void main()
+{
+ color = texture (inTexture, inTexCoord);
+}
--- /dev/null
+#version 420 core
+
+layout(location = 0) in vec4 inRect;
+layout(location = 1) in vec4 inTexRect;
+
+layout(push_constant) uniform PushConstants {
+ mat4 mvp;
+ vec4 clip_bounds;
+ vec4 clip_widths;
+ vec4 clip_heights;
+} push;
+
+layout(location = 0) out vec2 outTexCoord;
+
+out gl_PerVertex {
+ vec4 gl_Position;
+};
+
+vec2 offsets[6] = { vec2(0.0, 0.0),
+ vec2(1.0, 0.0),
+ vec2(0.0, 1.0),
+ vec2(0.0, 1.0),
+ vec2(1.0, 0.0),
+ vec2(1.0, 1.0) };
+
+vec4 intersect(vec4 a, vec4 b)
+{
+ a = vec4(a.xy, a.xy + a.zw);
+ b = vec4(b.xy, b.xy + b.zw);
+ vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
+ if (any (greaterThanEqual (result.xy, result.zw)))
+ return vec4(0.0,0.0,0.0,0.0);
+ return vec4(result.xy, result.zw - result.xy);
+}
+
+void main() {
+ vec4 rect = intersect(inRect, push.clip_bounds);
+ vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
+ gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
+
+ vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
+ rect.zw / inRect.zw);
+ texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
+ inTexRect.zw * texrect.zw);
+ outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
+}
--- /dev/null
+#version 420 core
+
+layout(location = 0) in vec2 inTexCoord;
+
+layout(set = 0, binding = 0) uniform sampler2D inTexture;
+
+layout(location = 0) out vec4 color;
+
+void main()
+{
+ color = texture (inTexture, inTexCoord);
+}
--- /dev/null
+#version 420 core
+
+layout(location = 0) in vec4 inRect;
+layout(location = 1) in vec4 inTexRect;
+
+layout(push_constant) uniform PushConstants {
+ mat4 mvp;
+ vec4 clip_bounds;
+ vec4 clip_widths;
+ vec4 clip_heights;
+} push;
+
+layout(location = 0) out vec2 outTexCoord;
+
+out gl_PerVertex {
+ vec4 gl_Position;
+};
+
+vec2 offsets[6] = { vec2(0.0, 0.0),
+ vec2(1.0, 0.0),
+ vec2(0.0, 1.0),
+ vec2(0.0, 1.0),
+ vec2(1.0, 0.0),
+ vec2(1.0, 1.0) };
+
+void main() {
+ vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+ gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
+
+ outTexCoord = inTexRect.xy + inTexRect.zw * offsets[gl_VertexIndex];
+}
+++ /dev/null
-#version 420 core
-
-layout(location = 0) in vec2 inTexCoord;
-
-layout(set = 0, binding = 0) uniform sampler2D inTexture;
-
-layout(location = 0) out vec4 color;
-
-void main()
-{
- color = texture (inTexture, inTexCoord);
-}
+++ /dev/null
-#version 420 core
-
-layout(location = 0) in vec2 inPosition;
-layout(location = 1) in vec2 inTexCoord;
-
-layout(push_constant) uniform PushConstants {
- mat4 mvp;
- vec4 clip_bounds;
- vec4 clip_widths;
- vec4 clip_heights;
-} push;
-
-layout(location = 0) out vec2 outTexCoord;
-
-out gl_PerVertex {
- vec4 gl_Position;
-};
-
-void main() {
- gl_Position = push.mvp * vec4 (inPosition, 0.0, 1.0);
- outTexCoord = inTexCoord;
-}